package logic

import (
	"context"
	"post/docker/mysql"

	"post/postrpc/internal/svc"
	"post/postrpc/postrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdatePasswordLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdatePasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePasswordLogic {
	return &UpdatePasswordLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdatePasswordLogic) UpdatePassword(in *postrpc.UpdatePasswordRequest) (*postrpc.UpdatePasswordResponse, error) {
	// todo: add your logic here and delete this line

	var findUser mysql.User
	//sms := cache.Rdb.Get(l.ctx, "sendSms").Val()
	//if sms != in.SendSmsCode {
	//	return nil, fmt.Errorf("短信验证码错误")
	//}
	mysql.DB.Debug().Where("mobile=?", in.Mobile).Find(&findUser)
	//if findUser.ID != 0 {
	//	return nil, fmt.Errorf("账号已存在,请前去注册")
	//}
	//if findUser.Password != in.NewPassword {
	//	return nil, fmt.Errorf("新密码与旧密码密码不一致")
	//}
	//if findUser.Password == in.Password {
	//	return nil, fmt.Errorf("两次密码一致")
	//}
	findUser.Password = in.Password
	mysql.DB.Debug().Updates(&findUser)
	return &postrpc.UpdatePasswordResponse{}, nil
}
